#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""


class Solution:
    """
    @param nums: An integer array
    @return: nothing
    """
    def recoverRotatedSortedArray(self, nums):
        split_idx = 0
        for idx, value in enumerate(nums[1:-1], 1):
            pre = nums[idx-1]
            next = nums[idx+1]
            if pre > value and value < next:
                split_idx = idx
                break

        if not split_idx:
            if nums[-1] < nums[-2]:
                split_idx = len(nums)
            else:
                split_idx = 0

        new_nums = nums[split_idx:] + list(nums[0:split_idx])
        nums[:] = new_nums[:]


def main():
    print("start main")
    s = Solution()
    # ret = s.recoverRotatedSortedArray([4,1,2,3])
    nums = [4, 5, 1, 2, 3]
    ret = s.recoverRotatedSortedArray(nums)
    print(nums)

if __name__ == "__main__":
    main()
